package View;

import Controller.AplicacaoInjecaoController;
import Controller.DiagnosticoController;
import Controller.PrescricaoController;
import Model.AplicacaoInjecao;
import Model.Diagnostico;
import Model.Prescricao;
import Report.Relatorio;
import VO.VOAplicacaoInjecao;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Tiago
 */
public class PrincipalView extends javax.swing.JDialog {
    DiagnosticoController dControl = new DiagnosticoController();
    PrescricaoController pControl = new PrescricaoController();
    AplicacaoInjecaoController aiControl = new AplicacaoInjecaoController();
    String dados[];
    java.sql.Date dataInicial, dataFinal;
    
    public PrincipalView(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo( null );
    }
    
    public void adicionarDataPesquisa(Date dInicial, Date dFinal){
        dataInicial = new java.sql.Date(dInicial.getTime());
        dataFinal = new java.sql.Date(dFinal.getTime());
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgPesquisaMedicamento = new javax.swing.ButtonGroup();
        bgPesquisaDiagnostico = new javax.swing.ButtonGroup();
        bgPesquisaPrescricao = new javax.swing.ButtonGroup();
        bgPesquisaAplicacaoInjecao = new javax.swing.ButtonGroup();
        pnTabela = new javax.swing.JPanel();
        spPrincipal = new javax.swing.JScrollPane();
        tbPrincipal = new javax.swing.JTable();
        tpPrincipal = new javax.swing.JTabbedPane();
        pnMedicamento = new javax.swing.JPanel();
        tfPesquisaMedicamento = new javax.swing.JTextField();
        lbPesquisaMedicamento = new javax.swing.JLabel();
        lbPesquisaPorMedicamento = new javax.swing.JLabel();
        rbPesquisaMedicamentoNome = new javax.swing.JRadioButton();
        rbPesquisaMedicamentoCaracteristica = new javax.swing.JRadioButton();
        rbPesquisaMedicamentoPrincipio = new javax.swing.JRadioButton();
        pnDiagnostico = new javax.swing.JPanel();
        tfPesquisaDiagnostico = new javax.swing.JTextField();
        lbPesquisaDiagnostico = new javax.swing.JLabel();
        lbPesquisaPorDiagnostico = new javax.swing.JLabel();
        rbPesquisaDiagnosticoNome = new javax.swing.JRadioButton();
        rbPesquisaDiagnosticoCaracteristica = new javax.swing.JRadioButton();
        pnPrescricao = new javax.swing.JPanel();
        tfPesquisaPrescricao = new javax.swing.JTextField();
        lbPesquisaPrescricao = new javax.swing.JLabel();
        lbPesquisaPorPrescricao = new javax.swing.JLabel();
        rbPesquisaPrescricaoNome = new javax.swing.JRadioButton();
        rbPesquisaPrescricaoCaracteristica = new javax.swing.JRadioButton();
        pnAplicacaoInjecao = new javax.swing.JPanel();
        tfPesquisaInjecao = new javax.swing.JTextField();
        lbPesquisaAplicação = new javax.swing.JLabel();
        lbPesquisaPorInjecao = new javax.swing.JLabel();
        rbPesquisaInjecaoUsuario = new javax.swing.JRadioButton();
        rbPesquisaInjecaoLancada = new javax.swing.JRadioButton();
        rbPesquisaInjecaoPendente = new javax.swing.JRadioButton();
        rbPesquisaInjecaoData = new javax.swing.JRadioButton();
        btPesquisaInjecaoData = new javax.swing.JButton();
        pnPrincipalBotao = new javax.swing.JPanel();
        btCadastrar = new javax.swing.JButton();
        btAlterar = new javax.swing.JButton();
        btExcluir = new javax.swing.JButton();
        mbPrincipal = new javax.swing.JMenuBar();
        mnCadastro = new javax.swing.JMenu();
        mnCadatrarMedicamento = new javax.swing.JMenuItem();
        mnCadastrarDiagnostico = new javax.swing.JMenuItem();
        mnCadastrarPrescricao = new javax.swing.JMenuItem();
        mnCadastrarOperador = new javax.swing.JMenuItem();
        mnGerar = new javax.swing.JMenu();
        mnGerarInjecao = new javax.swing.JMenuItem();
        mnGerarProntuario = new javax.swing.JMenuItem();
        mnImprimir = new javax.swing.JMenu();
        mnImprimirAplicacaoInjecao = new javax.swing.JMenuItem();
        mnLancar = new javax.swing.JMenu();
        mnLancarInjecao = new javax.swing.JMenuItem();
        mnLancarDiagnostico = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CAPS II - Farmácia");
        setName("dlPrincipal"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        tbPrincipal.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tbPrincipal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbPrincipalMousePressed(evt);
            }
        });
        spPrincipal.setViewportView(tbPrincipal);

        javax.swing.GroupLayout pnTabelaLayout = new javax.swing.GroupLayout(pnTabela);
        pnTabela.setLayout(pnTabelaLayout);
        pnTabelaLayout.setHorizontalGroup(
            pnTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(spPrincipal)
        );
        pnTabelaLayout.setVerticalGroup(
            pnTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(spPrincipal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        tpPrincipal.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tpPrincipalStateChanged(evt);
            }
        });
        tpPrincipal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tpPrincipalFocusGained(evt);
            }
        });

        lbPesquisaMedicamento.setText("Campo de pesquisa:");

        lbPesquisaPorMedicamento.setText("Pesquisar por:");

        bgPesquisaMedicamento.add(rbPesquisaMedicamentoNome);
        rbPesquisaMedicamentoNome.setSelected(true);
        rbPesquisaMedicamentoNome.setText("Nome");
        rbPesquisaMedicamentoNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaMedicamentoNomeActionPerformed(evt);
            }
        });

        bgPesquisaMedicamento.add(rbPesquisaMedicamentoCaracteristica);
        rbPesquisaMedicamentoCaracteristica.setText("Característica");
        rbPesquisaMedicamentoCaracteristica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaMedicamentoCaracteristicaActionPerformed(evt);
            }
        });

        bgPesquisaMedicamento.add(rbPesquisaMedicamentoPrincipio);
        rbPesquisaMedicamentoPrincipio.setText("Princípio Ativo");
        rbPesquisaMedicamentoPrincipio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaMedicamentoPrincipioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnMedicamentoLayout = new javax.swing.GroupLayout(pnMedicamento);
        pnMedicamento.setLayout(pnMedicamentoLayout);
        pnMedicamentoLayout.setHorizontalGroup(
            pnMedicamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnMedicamentoLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(pnMedicamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbPesquisaPorMedicamento)
                    .addComponent(lbPesquisaMedicamento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnMedicamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnMedicamentoLayout.createSequentialGroup()
                        .addComponent(rbPesquisaMedicamentoNome)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaMedicamentoCaracteristica)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaMedicamentoPrincipio))
                    .addComponent(tfPesquisaMedicamento, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(381, Short.MAX_VALUE))
        );
        pnMedicamentoLayout.setVerticalGroup(
            pnMedicamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnMedicamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnMedicamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfPesquisaMedicamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPesquisaMedicamento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnMedicamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPesquisaPorMedicamento)
                    .addComponent(rbPesquisaMedicamentoNome)
                    .addComponent(rbPesquisaMedicamentoCaracteristica)
                    .addComponent(rbPesquisaMedicamentoPrincipio))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tpPrincipal.addTab("Medicamentos", pnMedicamento);

        tfPesquisaDiagnostico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfPesquisaDiagnosticoKeyReleased(evt);
            }
        });

        lbPesquisaDiagnostico.setText("Campo de pesquisa:");

        lbPesquisaPorDiagnostico.setText("Pesquisar por:");

        bgPesquisaDiagnostico.add(rbPesquisaDiagnosticoNome);
        rbPesquisaDiagnosticoNome.setSelected(true);
        rbPesquisaDiagnosticoNome.setText("Nome");
        rbPesquisaDiagnosticoNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaDiagnosticoNomeActionPerformed(evt);
            }
        });

        bgPesquisaDiagnostico.add(rbPesquisaDiagnosticoCaracteristica);
        rbPesquisaDiagnosticoCaracteristica.setText("Característica");
        rbPesquisaDiagnosticoCaracteristica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaDiagnosticoCaracteristicaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnDiagnosticoLayout = new javax.swing.GroupLayout(pnDiagnostico);
        pnDiagnostico.setLayout(pnDiagnosticoLayout);
        pnDiagnosticoLayout.setHorizontalGroup(
            pnDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDiagnosticoLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(pnDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbPesquisaPorDiagnostico)
                    .addComponent(lbPesquisaDiagnostico))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnDiagnosticoLayout.createSequentialGroup()
                        .addComponent(rbPesquisaDiagnosticoNome)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaDiagnosticoCaracteristica))
                    .addComponent(tfPesquisaDiagnostico, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(381, Short.MAX_VALUE))
        );
        pnDiagnosticoLayout.setVerticalGroup(
            pnDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDiagnosticoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfPesquisaDiagnostico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPesquisaDiagnostico))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPesquisaPorDiagnostico)
                    .addComponent(rbPesquisaDiagnosticoNome)
                    .addComponent(rbPesquisaDiagnosticoCaracteristica))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tpPrincipal.addTab("Diagnósticos", pnDiagnostico);

        tfPesquisaPrescricao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfPesquisaPrescricaoKeyReleased(evt);
            }
        });

        lbPesquisaPrescricao.setText("Campo de pesquisa:");

        lbPesquisaPorPrescricao.setText("Pesquisar por:");

        bgPesquisaPrescricao.add(rbPesquisaPrescricaoNome);
        rbPesquisaPrescricaoNome.setSelected(true);
        rbPesquisaPrescricaoNome.setText("Nome");
        rbPesquisaPrescricaoNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaPrescricaoNomeActionPerformed(evt);
            }
        });

        bgPesquisaPrescricao.add(rbPesquisaPrescricaoCaracteristica);
        rbPesquisaPrescricaoCaracteristica.setText("Característica");
        rbPesquisaPrescricaoCaracteristica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaPrescricaoCaracteristicaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnPrescricaoLayout = new javax.swing.GroupLayout(pnPrescricao);
        pnPrescricao.setLayout(pnPrescricaoLayout);
        pnPrescricaoLayout.setHorizontalGroup(
            pnPrescricaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPrescricaoLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(pnPrescricaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbPesquisaPorPrescricao)
                    .addComponent(lbPesquisaPrescricao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnPrescricaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnPrescricaoLayout.createSequentialGroup()
                        .addComponent(rbPesquisaPrescricaoNome)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaPrescricaoCaracteristica))
                    .addComponent(tfPesquisaPrescricao, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(381, Short.MAX_VALUE))
        );
        pnPrescricaoLayout.setVerticalGroup(
            pnPrescricaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPrescricaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnPrescricaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfPesquisaPrescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPesquisaPrescricao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnPrescricaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPesquisaPorPrescricao)
                    .addComponent(rbPesquisaPrescricaoNome)
                    .addComponent(rbPesquisaPrescricaoCaracteristica))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tpPrincipal.addTab("Prescrições", pnPrescricao);

        tfPesquisaInjecao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfPesquisaInjecaoKeyReleased(evt);
            }
        });

        lbPesquisaAplicação.setText("Campo de pesquisa:");

        lbPesquisaPorInjecao.setText("Pesquisar por:");

        bgPesquisaAplicacaoInjecao.add(rbPesquisaInjecaoUsuario);
        rbPesquisaInjecaoUsuario.setSelected(true);
        rbPesquisaInjecaoUsuario.setText("Usuário");
        rbPesquisaInjecaoUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaInjecaoUsuarioActionPerformed(evt);
            }
        });

        bgPesquisaAplicacaoInjecao.add(rbPesquisaInjecaoLancada);
        rbPesquisaInjecaoLancada.setText("Lançadas");
        rbPesquisaInjecaoLancada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaInjecaoLancadaActionPerformed(evt);
            }
        });

        bgPesquisaAplicacaoInjecao.add(rbPesquisaInjecaoPendente);
        rbPesquisaInjecaoPendente.setText("Pendentes");
        rbPesquisaInjecaoPendente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaInjecaoPendenteActionPerformed(evt);
            }
        });

        bgPesquisaAplicacaoInjecao.add(rbPesquisaInjecaoData);
        rbPesquisaInjecaoData.setText("Data");
        rbPesquisaInjecaoData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPesquisaInjecaoDataActionPerformed(evt);
            }
        });

        btPesquisaInjecaoData.setText("Selecionar Data");
        btPesquisaInjecaoData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPesquisaInjecaoDataActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnAplicacaoInjecaoLayout = new javax.swing.GroupLayout(pnAplicacaoInjecao);
        pnAplicacaoInjecao.setLayout(pnAplicacaoInjecaoLayout);
        pnAplicacaoInjecaoLayout.setHorizontalGroup(
            pnAplicacaoInjecaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAplicacaoInjecaoLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(pnAplicacaoInjecaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbPesquisaPorInjecao)
                    .addComponent(lbPesquisaAplicação))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnAplicacaoInjecaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfPesquisaInjecao, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnAplicacaoInjecaoLayout.createSequentialGroup()
                        .addComponent(rbPesquisaInjecaoUsuario)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaInjecaoLancada)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaInjecaoPendente)
                        .addGap(18, 18, 18)
                        .addComponent(rbPesquisaInjecaoData)
                        .addGap(18, 18, 18)
                        .addComponent(btPesquisaInjecaoData)))
                .addContainerGap(381, Short.MAX_VALUE))
        );
        pnAplicacaoInjecaoLayout.setVerticalGroup(
            pnAplicacaoInjecaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAplicacaoInjecaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnAplicacaoInjecaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfPesquisaInjecao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPesquisaAplicação))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnAplicacaoInjecaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPesquisaPorInjecao)
                    .addComponent(rbPesquisaInjecaoUsuario)
                    .addComponent(rbPesquisaInjecaoLancada)
                    .addComponent(rbPesquisaInjecaoPendente)
                    .addComponent(rbPesquisaInjecaoData)
                    .addComponent(btPesquisaInjecaoData))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tpPrincipal.addTab("Aplicação de Injeção", pnAplicacaoInjecao);

        pnPrincipalBotao.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        btCadastrar.setText("Cadastrar");
        btCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCadastrarActionPerformed(evt);
            }
        });

        btAlterar.setText("Alterar");
        btAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarActionPerformed(evt);
            }
        });

        btExcluir.setText("Excluir");
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnPrincipalBotaoLayout = new javax.swing.GroupLayout(pnPrincipalBotao);
        pnPrincipalBotao.setLayout(pnPrincipalBotaoLayout);
        pnPrincipalBotaoLayout.setHorizontalGroup(
            pnPrincipalBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPrincipalBotaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(btAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(btExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnPrincipalBotaoLayout.setVerticalGroup(
            pnPrincipalBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnPrincipalBotaoLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(pnPrincipalBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        mnCadastro.setText("Cadastros");

        mnCadatrarMedicamento.setText("Medicamentos");
        mnCadatrarMedicamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadatrarMedicamentoActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadatrarMedicamento);

        mnCadastrarDiagnostico.setText("Diagnósticos");
        mnCadastrarDiagnostico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastrarDiagnosticoActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastrarDiagnostico);

        mnCadastrarPrescricao.setText("Prescrições");
        mnCadastrarPrescricao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastrarPrescricaoActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastrarPrescricao);

        mnCadastrarOperador.setText("Operador do Sistema");
        mnCadastrarOperador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastrarOperadorActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastrarOperador);

        mbPrincipal.add(mnCadastro);

        mnGerar.setText("Gerar");

        mnGerarInjecao.setText("Aplicação de Injeção");
        mnGerar.add(mnGerarInjecao);

        mnGerarProntuario.setText("Prontuário de Diagnósticos e Prescrições");
        mnGerar.add(mnGerarProntuario);

        mbPrincipal.add(mnGerar);

        mnImprimir.setText("Imprimir");

        mnImprimirAplicacaoInjecao.setText("Aplicação de Injeção");
        mnImprimirAplicacaoInjecao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnImprimirAplicacaoInjecaoActionPerformed(evt);
            }
        });
        mnImprimir.add(mnImprimirAplicacaoInjecao);

        mbPrincipal.add(mnImprimir);

        mnLancar.setText("Lançar");

        mnLancarInjecao.setText("Aplicação de Injeção");
        mnLancarInjecao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnLancarInjecaoActionPerformed(evt);
            }
        });
        mnLancar.add(mnLancarInjecao);

        mnLancarDiagnostico.setText("Diagnósticos ou Prescrições");
        mnLancarDiagnostico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnLancarDiagnosticoActionPerformed(evt);
            }
        });
        mnLancar.add(mnLancarDiagnostico);

        mbPrincipal.add(mnLancar);

        setJMenuBar(mbPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnTabela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tpPrincipal)
                    .addComponent(pnPrincipalBotao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(55, Short.MAX_VALUE)
                .addComponent(tpPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnTabela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnPrincipalBotao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        tbPrincipalMousePressed(null);
    }//GEN-LAST:event_formWindowActivated

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        
    }//GEN-LAST:event_formWindowOpened

    private void tpPrincipalFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tpPrincipalFocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_tpPrincipalFocusGained

    private void mnCadatrarMedicamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadatrarMedicamentoActionPerformed
        MedicamentoView m = new MedicamentoView(new javax.swing.JFrame(), true);;
        m.setVisible(true);
        tpPrincipalStateChanged(null);//Atualiza a tabela
    }//GEN-LAST:event_mnCadatrarMedicamentoActionPerformed

    private void mnCadastrarDiagnosticoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastrarDiagnosticoActionPerformed
        DiagnosticoView d = new DiagnosticoView(new javax.swing.JFrame(), true);;
        d.setVisible(true);
        tpPrincipalStateChanged(null);//Atualiza a tabela
    }//GEN-LAST:event_mnCadastrarDiagnosticoActionPerformed

    private void mnCadastrarPrescricaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastrarPrescricaoActionPerformed
        PrescricaoView p = new PrescricaoView(new javax.swing.JFrame(), true);;
        p.setVisible(true);
        tpPrincipalStateChanged(null);//Atualiza a tabela
    }//GEN-LAST:event_mnCadastrarPrescricaoActionPerformed

    private void mnCadastrarOperadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastrarOperadorActionPerformed
        OperadorView o = new OperadorView(new javax.swing.JFrame(), true);;
        o.setVisible(true);
    }//GEN-LAST:event_mnCadastrarOperadorActionPerformed

    private void mnLancarDiagnosticoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnLancarDiagnosticoActionPerformed
        DiagnosticoPrescricaoView d = new DiagnosticoPrescricaoView(new javax.swing.JFrame(), true);;
        d.setVisible(true);
        tpPrincipalStateChanged(null);//Atualiza a tabela
    }//GEN-LAST:event_mnLancarDiagnosticoActionPerformed

    private void mnLancarInjecaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnLancarInjecaoActionPerformed
        ImprimirAplicaçãoInjeçãoView a = new ImprimirAplicaçãoInjeçãoView(new javax.swing.JFrame(), false);
        a.setVisible(true);
        tpPrincipalStateChanged(null);//Atualiza a tabela
    }//GEN-LAST:event_mnLancarInjecaoActionPerformed

    private void tpPrincipalStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tpPrincipalStateChanged
        ResultSet rs;
        switch (tpPrincipal.getSelectedIndex()){
            case 0:
                carregarTabelaMedicamento(null);
                btAlterar.setText("Alterar");
                btExcluir.setEnabled(true);
                break;
            case 1:
                rs = dControl.obterListaDiagnostico();
                carregarTabelaDiagnostico(rs);
                btAlterar.setText("Alterar");
                btExcluir.setEnabled(true);
                break;
            case 2:
                rs = pControl.obterListaPrescricao();
                carregarTabelaPrescricao(rs);
                btAlterar.setText("Alterar");
                btExcluir.setEnabled(true);
                break;
            case 3:
                ArrayList<VOAplicacaoInjecao> lista = aiControl.obterAplicacao();
                carregarTabelaAplicacaoInjecao(lista);
                btAlterar.setText("Lançar");
                btExcluir.setEnabled(false);
                btPesquisaInjecaoData.setVisible(false);
                break;
        } 
    }//GEN-LAST:event_tpPrincipalStateChanged

    private void btCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCadastrarActionPerformed
        switch (tpPrincipal.getSelectedIndex()){
            case 0:
                mnCadatrarMedicamentoActionPerformed(evt);
                break;
            case 1:
                mnCadastrarDiagnosticoActionPerformed(evt);
                break;
            case 2:
                mnCadastrarPrescricaoActionPerformed(evt);
                break;
            case 3:
                mnLancarInjecaoActionPerformed(evt);
                break;
        }
    }//GEN-LAST:event_btCadastrarActionPerformed

    private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarActionPerformed
        if(btAlterar.getText().equals("Alterar")){ //Trata as alterações
            if(tbPrincipal.getSelectedRow() == -1){
                JOptionPane.showMessageDialog(null, "Selecione o registro que deseja alterar!");
            }
            else{
                int linha = tbPrincipal.getSelectedRow();
                switch (tpPrincipal.getSelectedIndex()){
                    case 0:
                        //Alterar MedicamentoView
                        break;
                    case 1:
                        DiagnosticoView d = new DiagnosticoView(null, rootPaneCheckingEnabled);
                        Diagnostico diag = dControl.instanciarObjetoDiagnostico();
                        d.codigo = Integer.parseInt(tbPrincipal.getModel().getValueAt(linha, 0).toString());
                        diag.setNome(tbPrincipal.getModel().getValueAt(linha, 1).toString());
                        diag.setCaracteristica(tbPrincipal.getValueAt(linha, 2).toString());
                        d.receberDadosDiagnostico(diag);
                        d.alterar = true;
                        d.setVisible(true);
                        break;
                    case 2:
                        PrescricaoView p = new PrescricaoView(null, rootPaneCheckingEnabled);
                        Prescricao presc = pControl.instanciarObjetoPrescricao();
                        p.codigo = Integer.parseInt(tbPrincipal.getModel().getValueAt(linha, 0).toString());
                        presc.setNome(tbPrincipal.getModel().getValueAt(linha, 1).toString());
                        presc.setCaracteristica(tbPrincipal.getModel().getValueAt(linha, 2).toString());
                        p.receberDadosPrescricao(presc);
                        p.alterar = true;
                        p.setVisible(true);
                        break;
                }
            }
        }
        else{ //Trata o lançamento da aplicação
            if(tbPrincipal.getSelectedRow() == -1){
                JOptionPane.showMessageDialog(null, "Selecione a aplicação que deseja lançar!");
            }
            else{
                int x = JOptionPane.showConfirmDialog(this,"Deseja lançar esse aplicação?", "CAPS II - Farmácia", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if(x == JOptionPane.OK_OPTION){
                    int linha = tbPrincipal.getSelectedRow();
                    AplicacaoInjecao aplic = new AplicacaoInjecao();
                    aplic.setCod_aplicacao(Integer.parseInt(tbPrincipal.getModel().getValueAt(linha, 0).toString()));
                    aiControl.lancarAplicacaoInjecao(aplic);
                }
            }
        }    
            tpPrincipalStateChanged(null);//Atualiza a tabela
        
    }//GEN-LAST:event_btAlterarActionPerformed

    private void tbPrincipalMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPrincipalMousePressed
        switch (tpPrincipal.getSelectedIndex()){
                case 0:
                    tfPesquisaMedicamento.requestFocus();
                    break;
                case 1:
                    tfPesquisaDiagnostico.requestFocus();
                    break;
                case 2:
                    tfPesquisaPrescricao.requestFocus();
                    break;
                case 3:
                    tfPesquisaInjecao.requestFocus();
                    break;
            }
    }//GEN-LAST:event_tbPrincipalMousePressed

    private void tfPesquisaDiagnosticoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfPesquisaDiagnosticoKeyReleased
        if(rbPesquisaDiagnosticoNome.isSelected()){
            ResultSet rs = dControl.pesquisarPorNome(tfPesquisaDiagnostico.getText());
            carregarTabelaDiagnostico(rs);
        }
        else if(rbPesquisaDiagnosticoCaracteristica.isSelected()){
            ResultSet rs = dControl.pesquisarPorCaracteristica(tfPesquisaDiagnostico.getText());
            carregarTabelaDiagnostico(rs);
        }
    }//GEN-LAST:event_tfPesquisaDiagnosticoKeyReleased

    private void rbPesquisaDiagnosticoNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaDiagnosticoNomeActionPerformed
        tfPesquisaDiagnostico.requestFocus();
    }//GEN-LAST:event_rbPesquisaDiagnosticoNomeActionPerformed

    private void rbPesquisaDiagnosticoCaracteristicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaDiagnosticoCaracteristicaActionPerformed
        tfPesquisaDiagnostico.requestFocus();
    }//GEN-LAST:event_rbPesquisaDiagnosticoCaracteristicaActionPerformed

    private void rbPesquisaMedicamentoNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaMedicamentoNomeActionPerformed
        tfPesquisaMedicamento.requestFocus();
    }//GEN-LAST:event_rbPesquisaMedicamentoNomeActionPerformed

    private void rbPesquisaMedicamentoCaracteristicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaMedicamentoCaracteristicaActionPerformed
        tfPesquisaMedicamento.requestFocus();
    }//GEN-LAST:event_rbPesquisaMedicamentoCaracteristicaActionPerformed

    private void rbPesquisaMedicamentoPrincipioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaMedicamentoPrincipioActionPerformed
        tfPesquisaMedicamento.requestFocus();
    }//GEN-LAST:event_rbPesquisaMedicamentoPrincipioActionPerformed

    private void rbPesquisaPrescricaoNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaPrescricaoNomeActionPerformed
        tfPesquisaPrescricao.requestFocus();
    }//GEN-LAST:event_rbPesquisaPrescricaoNomeActionPerformed

    private void rbPesquisaPrescricaoCaracteristicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaPrescricaoCaracteristicaActionPerformed
        tfPesquisaPrescricao.requestFocus();
    }//GEN-LAST:event_rbPesquisaPrescricaoCaracteristicaActionPerformed

    private void rbPesquisaInjecaoUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaInjecaoUsuarioActionPerformed
        btPesquisaInjecaoData.setVisible(false);
        lbPesquisaAplicação.setVisible(true);
        tfPesquisaInjecao.setVisible(true);
        tfPesquisaInjecao.setText("");
        tfPesquisaInjecao.requestFocus();
        ArrayList<VOAplicacaoInjecao> lista = aiControl.obterAplicacao();
        carregarTabelaAplicacaoInjecao(lista);
    }//GEN-LAST:event_rbPesquisaInjecaoUsuarioActionPerformed

    private void rbPesquisaInjecaoPendenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaInjecaoPendenteActionPerformed
        tfPesquisaInjecao.setVisible(false);
        lbPesquisaAplicação.setVisible(false);
        btPesquisaInjecaoData.setVisible(false);
        ArrayList<VOAplicacaoInjecao> lista = aiControl.obterAplicacaoPendente();
        carregarTabelaAplicacaoInjecao(lista);
    }//GEN-LAST:event_rbPesquisaInjecaoPendenteActionPerformed

    private void rbPesquisaInjecaoDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaInjecaoDataActionPerformed
        tfPesquisaInjecao.setVisible(false);
        lbPesquisaAplicação.setVisible(false);
        btPesquisaInjecaoData.setVisible(true);
    }//GEN-LAST:event_rbPesquisaInjecaoDataActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        if(tbPrincipal.getSelectedRow() == -1){
            JOptionPane.showMessageDialog(null, "Selecione o registro que deseja excluir!");
        }
        else{
            int x = JOptionPane.showConfirmDialog(this,"Deseja excluir esse registro?", "CAPS II - Farmácia", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if(x == JOptionPane.OK_OPTION){
                int linha = tbPrincipal.getSelectedRow();
                switch (tpPrincipal.getSelectedIndex()){
                    case 0:
                        //Alterar MedicamentoView
                        break;
                    case 1:
                        Diagnostico diag = dControl.instanciarObjetoDiagnostico();
                        diag.setCodigo(Integer.parseInt(tbPrincipal.getModel().getValueAt(linha, 0).toString()));
                        dControl.excluirDiagnostico(diag);
                        break;
                    case 2:
                        Prescricao presc = pControl.instanciarObjetoPrescricao();
                        presc.setCodigo(Integer.parseInt(tbPrincipal.getModel().getValueAt(linha, 0).toString()));
                        pControl.excluirPrescricao(presc);
                        break;
                    case 3:
                        //Alterar Injeção
                        break;
                }
            }
           tpPrincipalStateChanged(null);//Atualiza a tabela
        }
    }//GEN-LAST:event_btExcluirActionPerformed

    private void tfPesquisaPrescricaoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfPesquisaPrescricaoKeyReleased
        if(rbPesquisaPrescricaoNome.isSelected()){
            ResultSet rs = pControl.pesquisarPorNome(tfPesquisaPrescricao.getText());
            carregarTabelaPrescricao(rs);
        }
        else if(rbPesquisaPrescricaoCaracteristica.isSelected()){
            ResultSet rs = pControl.pesquisarPorCaracteristica(tfPesquisaPrescricao.getText());
            carregarTabelaPrescricao(rs);
        }
    }//GEN-LAST:event_tfPesquisaPrescricaoKeyReleased

    private void rbPesquisaInjecaoLancadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPesquisaInjecaoLancadaActionPerformed
        tfPesquisaInjecao.setVisible(false);
        lbPesquisaAplicação.setVisible(false);
        btPesquisaInjecaoData.setVisible(false);
        ArrayList<VOAplicacaoInjecao> lista = aiControl.obterAplicacaoLancada();
        carregarTabelaAplicacaoInjecao(lista);
    }//GEN-LAST:event_rbPesquisaInjecaoLancadaActionPerformed

    private void tfPesquisaInjecaoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfPesquisaInjecaoKeyReleased
        if(rbPesquisaInjecaoUsuario.isSelected()){
            ArrayList<VOAplicacaoInjecao> lista = aiControl.pesquisarPorUsuario(tfPesquisaInjecao.getText());
            carregarTabelaAplicacaoInjecao(lista);
        }
    }//GEN-LAST:event_tfPesquisaInjecaoKeyReleased

    private void btPesquisaInjecaoDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPesquisaInjecaoDataActionPerformed
        PesquisaInjecaoView p = new PesquisaInjecaoView(null, rootPaneCheckingEnabled, this);
        p.setVisible(true);
        ArrayList<VOAplicacaoInjecao> lista = aiControl.pesquisarPorData(dataInicial, dataFinal);
        carregarTabelaAplicacaoInjecao(lista);
    }//GEN-LAST:event_btPesquisaInjecaoDataActionPerformed

    private void mnImprimirAplicacaoInjecaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnImprimirAplicacaoInjecaoActionPerformed
        ImprimirAplicaçãoInjeçãoView i = new ImprimirAplicaçãoInjeçãoView(null, rootPaneCheckingEnabled);
        i.setVisible(true);
    }//GEN-LAST:event_mnImprimirAplicacaoInjecaoActionPerformed
    
    public void carregarTabelaMedicamento(ResultSet rs){
        String [] colunas = new String[]{"Nome", "Forma Farmacêutica", "Característica", "Princípio Ativo", "Via de Administração"};
        DefaultTableModel modelo = new DefaultTableModel(null, colunas){
            public boolean isCellEditable(int row, int col){
                return false;
            }
        };
        tbPrincipal.setModel(modelo);
        tbPrincipal.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
        /*try{
            while(rs.next()){
                modelo.addRow(new String[]{
                    rs.getString("cro"),
                    rs.getString("nome"),
                    rs.getString("especialidade")
                });
            }
        } catch (Exception e){
            System.out.println("PrincipalView - Erro: " + e.getMessage().toString());
        }*/
    }
    
    public void carregarTabelaDiagnostico(ResultSet rs){
        String [] colunas = new String[]{"Código", "Nome", "Característica"};
        DefaultTableModel modelo = new DefaultTableModel(null, colunas){
            public boolean isCellEditable(int row, int col){
                return false;
            }
        };
        tbPrincipal.setModel(modelo);
        tbPrincipal.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tbPrincipal.getColumnModel().getColumn(0).setPreferredWidth((int) (pnTabela.getWidth()* 0.1));
        tbPrincipal.getColumnModel().getColumn(1).setPreferredWidth((int) (pnTabela.getWidth()* 0.45));
        tbPrincipal.getColumnModel().getColumn(2).setPreferredWidth((int) (pnTabela.getWidth()* 0.45));
        try{
            while(rs.next()){
                modelo.addRow(new String[]{
                    rs.getString("cod_diagnostico"),
                    rs.getString("nome_diagnostico"),
                    rs.getString("caracteristica_diagnostico")
                });
            }
        } catch (Exception e){
            System.out.println("Principal - Erro: " + e.getMessage().toString());
        }
    }
    
    public void carregarTabelaPrescricao(ResultSet rs){
        String [] colunas = new String[]{"Código", "Nome", "Característica"};
        DefaultTableModel modelo = new DefaultTableModel(null, colunas){
            public boolean isCellEditable(int row, int col){
                return false;
            }
        };
        tbPrincipal.setModel(modelo);
        tbPrincipal.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tbPrincipal.getColumnModel().getColumn(0).setPreferredWidth((int) (pnTabela.getWidth()* 0.1));
        tbPrincipal.getColumnModel().getColumn(1).setPreferredWidth((int) (pnTabela.getWidth()* 0.45));
        tbPrincipal.getColumnModel().getColumn(2).setPreferredWidth((int) (pnTabela.getWidth()* 0.45));
        try{
            while(rs.next()){
                modelo.addRow(new String[]{
                    rs.getString("cod_prescricao"),
                    rs.getString("nome_prescricao"),
                    rs.getString("caracteristica_prescricao")
                });
            }
        } catch (Exception e){
            System.out.println("PrincipalView - Erro: " + e.getMessage().toString());
        }
    }
    
    public void carregarTabelaAplicacaoInjecao(ArrayList<VOAplicacaoInjecao> lista){
        String [] colunas = new String[]{"Código da Aplicação", "Código da Receita", "Usuário", "Braço", "Data", "Situação"};
        DefaultTableModel modelo = new DefaultTableModel(null, colunas){
            public boolean isCellEditable(int row, int col){
                return false;
            }
        };
        tbPrincipal.setModel(modelo);
        tbPrincipal.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tbPrincipal.getColumnModel().getColumn(0).setPreferredWidth((int) (pnTabela.getWidth()* 0.1));
        tbPrincipal.getColumnModel().getColumn(1).setPreferredWidth((int) (pnTabela.getWidth()* 0.095));
        tbPrincipal.getColumnModel().getColumn(2).setPreferredWidth((int) (pnTabela.getWidth()* 0.5));
        tbPrincipal.getColumnModel().getColumn(3).setPreferredWidth((int) (pnTabela.getWidth()* 0.1));
        tbPrincipal.getColumnModel().getColumn(4).setPreferredWidth((int) (pnTabela.getWidth()* 0.1));
        tbPrincipal.getColumnModel().getColumn(5).setPreferredWidth((int) (pnTabela.getWidth()* 0.1));
        try{
            for(VOAplicacaoInjecao apVO:lista){
                String[] linha = new String[]{apVO.getCodAplicacao(),
                                              apVO.getCodReceita(),
                                              apVO.getNomeUsuario(),
                                              apVO.getBraco(),
                                              apVO.getDataAplicacao(),
                                              apVO.getSituacao()};
                modelo.addRow(linha);
            }
        } catch (Exception e){
            System.out.println("PrincipalView - Erro: " + e.getMessage().toString());
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        //Ativa a skin no projeto
        try {
            javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                PrincipalView dialog = new PrincipalView(new javax.swing.JFrame(), false);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                Toolkit toolkit = Toolkit.getDefaultToolkit();    
                Dimension screenSize = toolkit.getScreenSize();    
                dialog.setBounds(0, 0, screenSize.width, screenSize.height - 32);
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgPesquisaAplicacaoInjecao;
    private javax.swing.ButtonGroup bgPesquisaDiagnostico;
    private javax.swing.ButtonGroup bgPesquisaMedicamento;
    private javax.swing.ButtonGroup bgPesquisaPrescricao;
    private javax.swing.JButton btAlterar;
    private javax.swing.JButton btCadastrar;
    private javax.swing.JButton btExcluir;
    private javax.swing.JButton btPesquisaInjecaoData;
    private javax.swing.JLabel lbPesquisaAplicação;
    private javax.swing.JLabel lbPesquisaDiagnostico;
    private javax.swing.JLabel lbPesquisaMedicamento;
    private javax.swing.JLabel lbPesquisaPorDiagnostico;
    private javax.swing.JLabel lbPesquisaPorInjecao;
    private javax.swing.JLabel lbPesquisaPorMedicamento;
    private javax.swing.JLabel lbPesquisaPorPrescricao;
    private javax.swing.JLabel lbPesquisaPrescricao;
    private javax.swing.JMenuBar mbPrincipal;
    private javax.swing.JMenuItem mnCadastrarDiagnostico;
    private javax.swing.JMenuItem mnCadastrarOperador;
    private javax.swing.JMenuItem mnCadastrarPrescricao;
    private javax.swing.JMenu mnCadastro;
    private javax.swing.JMenuItem mnCadatrarMedicamento;
    private javax.swing.JMenu mnGerar;
    private javax.swing.JMenuItem mnGerarInjecao;
    private javax.swing.JMenuItem mnGerarProntuario;
    private javax.swing.JMenu mnImprimir;
    private javax.swing.JMenuItem mnImprimirAplicacaoInjecao;
    private javax.swing.JMenu mnLancar;
    private javax.swing.JMenuItem mnLancarDiagnostico;
    private javax.swing.JMenuItem mnLancarInjecao;
    private javax.swing.JPanel pnAplicacaoInjecao;
    private javax.swing.JPanel pnDiagnostico;
    private javax.swing.JPanel pnMedicamento;
    private javax.swing.JPanel pnPrescricao;
    private javax.swing.JPanel pnPrincipalBotao;
    private javax.swing.JPanel pnTabela;
    private javax.swing.JRadioButton rbPesquisaDiagnosticoCaracteristica;
    private javax.swing.JRadioButton rbPesquisaDiagnosticoNome;
    private javax.swing.JRadioButton rbPesquisaInjecaoData;
    private javax.swing.JRadioButton rbPesquisaInjecaoLancada;
    private javax.swing.JRadioButton rbPesquisaInjecaoPendente;
    private javax.swing.JRadioButton rbPesquisaInjecaoUsuario;
    private javax.swing.JRadioButton rbPesquisaMedicamentoCaracteristica;
    private javax.swing.JRadioButton rbPesquisaMedicamentoNome;
    private javax.swing.JRadioButton rbPesquisaMedicamentoPrincipio;
    private javax.swing.JRadioButton rbPesquisaPrescricaoCaracteristica;
    private javax.swing.JRadioButton rbPesquisaPrescricaoNome;
    private javax.swing.JScrollPane spPrincipal;
    private javax.swing.JTable tbPrincipal;
    private javax.swing.JTextField tfPesquisaDiagnostico;
    private javax.swing.JTextField tfPesquisaInjecao;
    private javax.swing.JTextField tfPesquisaMedicamento;
    private javax.swing.JTextField tfPesquisaPrescricao;
    private javax.swing.JTabbedPane tpPrincipal;
    // End of variables declaration//GEN-END:variables
}
